<template>
  <!-- 欢迎栏信息 -->
  <div id="welcome">
    <!-- <div class="bg"></div> -->
    <img :src="require('/public/img/home_bg.webp')" alt="" class="bg" />
    <div class="info">
      <p class="name">{{ userInfo.userName }}<span>您好！欢迎登陆</span></p>
      <p class="time">登陆于：{{ newTime }}</p>
    </div>
  </div>
</template>
<script>

const days = ['天', '一', '二', '三', '四', '五', '六'] // 星期数组
let icnow = new Date()      // 初始化时间
let interval
export default {
  name: 'welcome',
  data () {
    return {
      userInfo: {},
      year: icnow.getFullYear(),
      month: icnow.getMonth() + 1,
      date: icnow.getDate(),
      day: days[icnow.getDay() - 1],
      time: icnow.toTimeString().substring(0, 8)
    }
  },
  mounted () {
    this.userInfo = this.$TOOL.data.get("USER_INFO")
  },
  created () {
    interval = setInterval(() => {
      let icnow = new Date()
      this.year = icnow.getFullYear()
      this.month = icnow.getMonth() + 1
      this.date = icnow.getDate()
      this.day = days[icnow.getDay()]
      this.time = icnow.toTimeString().substring(0, 8)
    }, 1000)
  },
  computed: {
    // 当前时间
    newTime: function () {
      return this.year + '年' + this.month + '月' + this.date + '日 星期' + this.day + ' ' + this.time
    }
  },
  beforeDestroy () {
    clearInterval(interval)
  }

}
</script>
<style lang="scss" scoped>
#welcome {
  position: relative;
  margin-bottom: 20px;
  height: 180px;
  box-sizing: border-box;
  border-radius: 20px;
  overflow: hidden;

  .bg {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
  .info {
    position: absolute;
    left: 5%;
    top: 50%;
    transform: translateY(-50%);
    font-size: 16px;
    line-height: 2em;
    color: #fff;
  }
  .name {
    font-size: 24px;
    margin-bottom: 10px;
    span {
      margin-left: 20px;
      font-size: 16px;
    }
  }
}
</style>